﻿using System;
using System.Collections.Generic;
using Gameplay.PVE.Effect;
using TMPro;
using UnityEngine;
using Yoozoo.Framework.Core;
using Yoozoo.Managers.ResourceManagerV2.Runtime;

namespace Gameplay.PVE.Survivor
{
    /// <summary>
    /// 战斗中的飘字代理器
    /// </summary>
    public class BattleFlyTextObject : BattleGameObject
    {
        public TextMeshPro tmpComponent;
        public Animation animation;
        private string text;
        
        public void SetText(string text)
        {
            this.text = text;
            if (IsReady)
            {
                tmpComponent.text = text;
            }
        }

        public void Play()
        {
            if (IsReady)
            {
                animation.Play();
            }
        }

        protected override void OnGameObjectCreatedInternal(GameObject gameObject)
        {
            tmpComponent = gameObject.GetComponentInChildren<TextMeshPro>();
            animation = gameObject.GetComponentInChildren<Animation>();
        }

        protected override void OnGameObjectReadyInternal(GameObject gameObject)
        {
            if (!string.IsNullOrEmpty(text))
            {
                tmpComponent.text = text;
            }
            Parent = FlyTextManager.Instance.Root;
            gameObject.transform.SetParent(FlyTextManager.Instance.Root);
            Play();
        }
        
        protected override void OnGameObjectReleaseInternal()
        {
            text = null;
        }

        protected override void OnGameObjectDestroyInternal()
        {

        }

    
    }
}
